/******************************************************************************

	COPYRIGHT(C) JONAS 'SORTIE' TERMANSEN 2010.

	This file is part of Maxsi Engine.

	Maxsi Engine is free software: you can redistribute it and/or modify it
	under the terms of the GNU Lesser General Public License as published by
	the Free Software Foundation, either version 3 of the License, or (at your
	option) any later version.

	Maxsi engine is distributed in the hope that it will be useful, but WITHOUT
	ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
	FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
	for more details.

	You should have received a copy of the GNU Lesser General Public License
	along with Maxsi Engine. If not, see <http://www.gnu.org/licenses/>.

	MaxsiEngine.dll
	A general purpose C++ library for the Maxsi Technology Project.

	MaxsiTypes.h
	Defines useful datatypes used across the Maxsi Engine projects.

******************************************************************************/

#ifndef MaxsiTypes_H
#define MaxsiTypes_H

BeginMaxsiNamespace

//=============================================================================
//	Defines.
//=============================================================================
#define INDEX_T_SIZE_T		0
#define INDEX_T_CHAR		1
#define INDEX_T_WCHAR_T		2
#define INDEX_T_USEDSHIFT	2 // The lowest INDEX_T_USEDSHIFT bits are reserved.
#define INDEX_T_USEDBITMASK	(1 << (INDEX_T_USEDSHIFT-1))

//=============================================================================
//	Hacks to ease porting from __intn to intn_t
//=============================================================================
#if defined(__GNUC__) && !defined(Maxsi_Support_MinGW)
//typedef unsigned int UINT;
typedef unsigned char BYTE;
#endif

//=============================================================================
//	Basic integer-based datatypes.
//=============================================================================
typedef uint64_t		Bytes_t;
typedef uint64_t		Speed_t; // dBytes_t/dt
typedef uint64_t		FileSize_t;
typedef uint8_t			FLAGS8;
typedef uint16_t		FLAGS16;
typedef uint32_t		FLAGS32;
typedef uint64_t		FLAGS64;
typedef uint_fast32_t	FLAGSL8;
typedef uint_fast32_t	FLAGSL16;
typedef uint_fast32_t	FLAGSL32;
typedef uint_fast64_t	FLAGSL64;
typedef	uint32_t		IPv4;
typedef unsigned long	StringType_t;
typedef unsigned long	MaxsiError;
typedef size_t			Word_t;

//=============================================================================
//	Declare a type for storing internal time offsets!
//=============================================================================
#ifdef WIN32
typedef DWORD Time_t;
#elif defined(Maxsi_Support_POSIX)
#define Time_t struct timeval
//typedef struct timeval Time_t;
#else
#error "Time_t is not declared on this platform!"
typedef long Time_t;
#endif

//=============================================================================
//	Define limits.
//=============================================================================
#define FILESIZE_MIN 0
#define FILESIZE_MAX UINT64_MAX

//=============================================================================
//	Declare a simple pointer type that we can use to cast to and from all sorts
//	of various pointer types, this allows us to do all sorts of awesome stuff.
//=============================================================================
struct _MaxsiHandle { int unused; };

typedef _MaxsiHandle* MaxsiHandle;

//=============================================================================
//	Index_t - Identifies a member in an array.
//=============================================================================
STRUCTLINKCPP Index_t
{
public:
	//=============================================================================
	//	Data Members.
	//=============================================================================
	FLAGS32		Type;
	void*		Index;

public:
	//=============================================================================
	//	bool IsDataType();
	//	
	//	Returns whether the Index type would qualify as DataType.
	//=============================================================================
	const bool	IsSize();
	const bool	IsChar();
	const bool	IsWChar();
	const bool	IsString();

public:
	//=============================================================================
	//	DataType IndexDataType();
	//
	//	Returns the actual Index of the Index as DataType. Returns 0 or NULL if the
	//	data type of this Index was not the requested. Does not allocate any new
	//	memory and should only be used within the scope of this index.
	//=============================================================================
	size_t		IndexSize();
	char*		IndexChar();
	wchar_t*	IndexWChar();

public:
	//=============================================================================
	//	bool Compare(Datatype CompareTo);
	//=============================================================================
	const bool	Compare(const size_t CompareTo);
	const bool	Compare(const char* CompareTo);
	const bool	Compare(const wchar_t* CompareTo);

public:
	//=============================================================================
	//	Index_t& operator=(const Index_t &rhs);
	//
	//	Assignment operator - Assigns this operator to the right hand statement.
	//=============================================================================
	Index_t&	operator=(const Index_t &rhs);
	Index_t&	operator=(const size_t &rhs);
	Index_t&	operator=(const char* &rhs);
	Index_t&	operator=(const wchar_t* &rhs);

public:
	//=============================================================================
	//	const bool	operator==(const Index_t &other);
	//
	//	Compares this index to another index (or type that can be cast to an index)
	//	and returns whether they point to the same entry, under the assumption that
	//	they are both indices in the same array. Returns true if identical.
	//=============================================================================
	const bool	operator==(const Index_t &other);
	const bool	operator==(const size_t &other);
	const bool	operator==(const char* &other);
	const bool	operator==(const wchar_t* &other);

public:
	//=============================================================================
	//	const bool	operator!=(const Index_t &other);
	//
	//	Compares this index to another index (or type that can be cast to an index)
	//	and returns whether they point to the same entry, under the assumption that
	//	they are both indices in the same array. Returns true if different.
	//=============================================================================
	const bool	operator!=(const Index_t &other);
	const bool	operator!=(const size_t &other);
	const bool	operator!=(const char* &other);
	const bool	operator!=(const wchar_t* &other);

};

//=============================================================================
//	Callback functions
//=============================================================================
#ifdef _WIN32
typedef bool (__cdecl* ProgressFunc_Type)(int);
#else
typedef bool (* ProgressFunc_Type)(int);
#endif

EndMaxsiNamespace

#endif
